#!/bin/bash
 function init() {
#mysql_init
source ${env_conf}/bin/activate || . ${env_conf}/bin/activate
cd ${project_conf}
python manage.py schemamigration desktop.apps.account --init
python manage.py schemamigration desktop.apps.ansible --init
python manage.py syncdb
python manage.py migrate ansible
python manage.py migrate account
python manage.py migrate kombu.transport.django
python manage.py migrate djcelery
python manage.py migrate guardian
}
function start() {
DAEMON=${env_conf}/bin/uwsgi
UWSGI_LOG=/var/log/uwsgi
[ -f ${UWSGI_LOG} ]||mkdir -p ${UWSGI_LOG}
uwsgi_ini=${project_conf}/ansible_uwsgi.ini
$DAEMON --ini $uwsgi_ini -d ${UWSGI_LOG}/ansible_ui.log 2>&1
/usr/sbin/nginx -c /etc/nginx/nginx.conf 2>&1
[[ -d ${project_conf}/cretential ]] && find ${project_conf}/cretential -name id_dsa| xargs chmod 700
su - ansible -c "${env_conf}/bin/supervisord -c ${project_conf}/celery-conf/supervisord.conf 2>&1"
}
project_conf=/usr/local/ansible_ui
env_conf=/usr/local/envansible

if [[ $# -eq 1 ]];then
case $1 in
start)
start
;;
init)
init
;;
*)
echo 'not exist parameter!'
;;
esac
else
echo "Usage $0 [init|start]"
fi
tail -f /dev/null

